var app = getApp(),

  $ = require("../../utils/httpHelper.js")
Page({
  data: {
    isMore:false,
    ismain:{},
    other:[],
    orderno:''
  },
  onShareAppMessage: function (res) {
    app.shareApp(res)
  },
  onLoad: function (options) {
    let that = this
    setTimeout(function(){
      if (!app.check_empty(options.scene)) {
        $.httpPost("check_class", { order_no: options.scene, rd_session: app.globalData.userInfo.rd_session, }, (data, err) => {
          if(data.result == 'success'){
            let list = data.list
            let other = []
            let main = []
            for (let item of list) {
              if (item.is_main == 'y') {
                main.push(item)
              } else {
                other.push(item)
              }
            }
            if (list.length == 1) {
              that.setData({
                isMore: false,
                ismain: main[0],
                orderno: options.scene
              })
            } else if (list.length > 1) {
              that.setData({
                isMore: true,
                other: other,
                ismain: main[0],
                orderno: options.scene
              })
            }
          }else{
            wx.showModal({
              title: '提示',
              content: data.message,
              success: function (res) {
                if (res.confirm) {
                  wx.switchTab({
                    url: '/pages/index/index',
                  })
                } else if (res.cancel) {
                  wx.switchTab({
                    url: '/pages/index/index',
                  })
                }
              }
            })
          }
          
          
        })
      }
    },1000)
   
    
  },
  queren(){
    $.httpPost("finish_class", { order_no: this.data.orderno, rd_session: app.globalData.userInfo.rd_session, }, (data, err) => {
      if(data.result == 'success'){
        wx.showToast({
          title: '成功~',
        })
        wx.switchTab({
          url: '/pages/index/index',
        })
      }else{
        wx.showToast({
          title: data.message,
        })
      }
    })
  }
});